#ifndef SINGLETON_H_
#define SINGLETON_H_

#include <iostream>
#include <cstdlib>
#include <list>
#include "Guard.h"




using namespace std;
template <class T>
class Singleton
{
public:
	typedef T		object_t;
	virtual ~Singleton()
	{

	}

	static T& getInstance()
	{
		if( _singleInstance == NULL )
		{
			Guard guard(_lock);
			if( _singleInstance == NULL )
			{
				_singleInstance = new T();
			}

		}

		return *_singleInstance;

	}
private:
	Singleton() {}
	Singleton(const Singleton&) {}
	Singleton& operator= (const Singleton& ) { }

private:
	static T*	_singleInstance;
	static Lock				_lock;
};
template<class T>
typename Singleton<T>::object_t* Singleton<T>::_singleInstance = NULL;

template<class T>
Lock Singleton<T>::_lock;



#endif